package com.tzy.note.base.thread.sum;

import java.util.concurrent.*;

//回顾总结线程的创建
public class NewThread {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //1.继承Thread类
        new MyThread1().start();

        //2.实现Runnable接口
        new Thread(new MyThread2()).start();

        //3.实现Callable接口
        FutureTask<Integer> futureTask = new FutureTask(new MyThread3());
        new Thread(futureTask).start();
        Integer integer = futureTask.get();
        System.out.println(integer);

        //4.使用线程池
        ExecutorService service = Executors.newFixedThreadPool(5);
        Future<Integer> future = service.submit(new MyThread3());
        Integer integer1 = future.get();
        System.out.println(integer1);
    }
}

//1.继承Thread类
class MyThread1 extends Thread{
    @Override
    public void run() {
        System.out.println("MyThread1");
    }
}
//2.实现Runnable接口
class MyThread2 implements Runnable{
    @Override
    public void run() {
        System.out.println("MyThread2");
    }
}


//3.实现Callable接口
class MyThread3 implements Callable{
    @Override
    public Integer call() throws Exception {
        System.out.println("MyThread3");
        return 100;
    }
}
